﻿<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd"> 
<html> 
<head>
<title>天气预报插件(设置)</title>
<style>
p{font-size:12px;}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script type="text/javascript" src="http://m.weather.com.cn/js/ajax_1.4.5.js"></script> 
<script type="text/javascript" src="menus1.js"></script> 
<script type="text/javascript">
function delCookie(name)
{
    var exp = new Date();
    exp.setTime(exp.getTime() - 1);
    var cval=getCookie(name);
    if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString();
}
function getCookie(name)
{
    var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
     if(arr != null) return unescape(arr[2]); return null;
}
function getcity(){
	if (document.getElementById('ckbDsCodeMode').checked){
		localStorage.setItem("dsCodeMode","1");
		
		delCookie('newcity1');
		chrome.extension.getBackgroundPage().loadDsCodeMode(true);
		chrome.extension.getBackgroundPage().loadWeather();
		alert('save success!');
		return;
	}
	else {
		localStorage.setItem("dsCodeMode","");
	}
	
  var time;
  var date;
  var obj = document.getElementById("city3");
  var strsel = obj.options[obj.selectedIndex].text;
  if (strsel=="县"){
	alert ("请选择您要定制的城市");
  }
  else {
	var timeSpan = document.getElementById('txtTimeSpan').value;
	timeSpan = parseInt(timeSpan);
	if (isNaN(timeSpan)){
		alert('刷新间隔必须是数字');
		return;
    }
	
	localStorage.setItem('timeSpan',timeSpan);
	
//	var city3 = document.getElementById("city3");
//	var ogg = document.getElementById("city4");
//	var std = ogg.options[ogg.selectedIndex].text;
//	time=new Date();
//	time.setTime(time.getTime()+365*24*60*60*1000*10);
//	date=time.toGMTString();
//	document.cookie = 'newcity1=' + escape(std)+ ';expires='+date;
	
   var selectCityList = document.getElementById('selectCityList');
   var cityList = "";
   var cityNameList = "";
   for (var i=0;i<selectCityList.options.length;i++){
      cityList+=","+selectCityList.options[i].value;
      cityNameList += ','+selectCityList.options[i].innerText;
   }
   
   cityList = cityList.substr(1);
   cityNameList = cityNameList.substr(1);
   
	localStorage["cityList"] = cityList;
	localStorage["cityNameList"] = cityNameList;
	localStorage['dateSelect'] = document.getElementById('selDate').value;
	localStorage['showLunar'] = document.getElementById('showLunar').checked ? "1" : "0";
	localStorage['showInTab'] = document.getElementById('showInTab').checked ? "1" : "0";
	localStorage['dayCount'] = document.getElementById('dayCount').value;

	// 改变当前
	chrome.extension.getBackgroundPage().loadSetting();
	chrome.extension.getBackgroundPage().loadDsCodeMode(false);
	chrome.extension.getBackgroundPage().timeSpan = timeSpan;
	chrome.extension.getBackgroundPage().loadWeather();
	
	alert('保存成功');
 }
}
function init(){
	var dateSelect = localStorage.getItem('dateSelect');
	var timeSpan = localStorage.getItem('timeSpan') || 20;
	var showLunar = localStorage["showLunar"];
	var showInTab = localStorage["showInTab"];
	var dayCount = localStorage["dayCount"] || "5";
	if (dateSelect){
		document.getElementById('selDate').value = dateSelect;
		document.getElementById('txtTimeSpan').value = timeSpan;
		document.getElementById('showLunar').checked = (showLunar == "1");
		document.getElementById('showInTab').checked = (showInTab == "1");
		document.getElementById('dayCount').value = dayCount;
		
	    var cityList = localStorage["cityList"];
	    var cityNameList = localStorage["cityNameList"];
	   
	    var arrs = cityList.split(/\,/g);
	    var arrNames = cityNameList.split(/\,/g);

	    for (var i = 0; i < arrs.length; i++) {
	        if (arrs[i]) {
	            document.getElementById('selectCityList').options.add(new Option(arrNames[i], arrs[i]));
	        }
	    }
	}
	
	if (localStorage.getItem("dsCodeMode") == "1"){
		document.getElementById('ckbDsCodeMode').checked = true;
		DoDsCodeMode(true);
	}
}
function DoDsCodeMode(dsCodeMode){
	if (dsCodeMode){
		document.getElementById('advanceSet').style.display = 'none';
		document.getElementById('btnSave').value = 'save';
		
		document.getElementById('lblTitle').innerHTML = 'china weather extension';
		document.getElementById('lblSetting').innerHTML = '(setting)';
		document.getElementById('lblAuthor').innerHTML = 'author:zhucai';
		document.getElementById('lblEmail').innerHTML = 'email:zhucai+weather1@gmail.com';
		document.getElementById('lblDataSrc').innerHTML = 'data source:http://www.weather.com.cn';
	}
	else {
		document.getElementById('advanceSet').style.display = '';
		document.getElementById('btnSave').value = '保存';
		
		document.getElementById('lblTitle').innerHTML = '天气预报插件';
		document.getElementById('lblSetting').innerHTML = '(设置)';
		document.getElementById('lblAuthor').innerHTML = '作者：朱才';
		document.getElementById('lblEmail').innerHTML = '邮箱：zhucai+weather1@gmail.com';
		document.getElementById('lblDataSrc').innerHTML = '数据来源：<a href="http://www.weather.com.cn/" target="_blank">中国天气网</a>';
	}
}
var cityIndex = 0;
function addCity(){
//   cityIndex++;
//   var city = document.getElementById("pCity");
//   var newCity = document.createElement("p");
//   newCity.innerHTML = city.innerHTML.replace("city","city"+cityIndex);;
//   city.parentElement.appendChild(newCity);
	var city3 = document.getElementById("city3");
	var ogg = document.getElementById("city4");
	
   var selectCityList = document.getElementById('selectCityList');
   selectCityList.options.add(new Option(city3.options[city3.selectedIndex].text,ogg.options[ogg.selectedIndex].text));
}
</script> 
</head> 
<body onload="init()">
<div style="width:500px;margin:0px auto;">
<h1 style="text-align:center"><span id="lblTitle">天气预报插件</span><span id="lblSetting" style="font-size:14px;">(设置)</span></h1>
english simple mode<input type="checkbox" id="ckbDsCodeMode" onchange="DoDsCodeMode(this.checked)">
<div id="advanceSet">
<div id="cityDiv">
<p style="border:1px solid #999999;padding:10px;" id="pCity"><em id="city"></em><button type="button" onclick="addCity()">增加到列表</button><br />
预定城市列表：
<select id="selectCityList" multiple="multiple" ondblclick="this.options.remove(this.selectedIndex);"></select>
(双击删除)
</p>
</div>
<p> </p>
<p>需要显示的天数：
<select id="dayCount">
<option value="2">2天</option>
<option value="3">3天</option>
<option value="4">4天</option>
<option value="5" selected="selected">5天</option>
</select></p>
<p>刷新间隔时间：<input type="text" id="txtTimeSpan" style="width:40px" value="20">(单位：分钟)</p>
<p>浏览器按钮图标(位于地址栏右侧)显示的日期：<select id="selDate">
<option value="today">今天</option>
<option value="tomorrow">明天</option>
</select></p>
<p>
<label for="showLunar">总是显示万年历</label><input type="checkbox" id="showLunar" />
</p>
<p>
<label for="showInTab">在标签页打开</label><input type="checkbox" id="showInTab" />
</p>
</div>
<p style="text-align:center;"><input type="submit" id="btnSave" value="保存" onclick ="getcity();"  class="button"> </p>
<p id="lblAuthor">作者：朱才</p>
<p id="P1">微博：<a href="http://weibo.com/zhucai" target="_blank">http://weibo.com/zhucai</a></p>
<p id="lblDataSrc">数据来源：<a href="http://www.weather.com.cn/" target="_blank">中国天气网</a></p>
</div>
<script src='http://www.google-analytics.com/ga.js' type='text/javascript'></script>
<script type="text/javascript">
  try{
  var pageTracker = _gat._getTracker("UA-30677288-1");
  pageTracker._trackPageview();
  } catch(err) {}
</script>
</body> 
</html>